﻿using System;
using System.Collections.Generic;
using com.uplus.common;
using com.uplus.data;

namespace WebApi
{
    /// <summary>
    /// 业务处理基类
    /// </summary>
    public abstract partial class BizBase
    {
        static Dictionary<Type, BizBase> Svcs = new Dictionary<Type, BizBase>();
        /// <summary>
        /// DaStatic
        /// </summary>
        public static DAMsSql DaStatic
        {
            get
            {
                return new DAMsSql(DBMain);
            }
        }
        static string lockStr = "lock";

        #region 获取相应服务
        /// <summary>
        /// 获取相应服务
        /// </summary>
        /// <typeparam name="T">服务类型</typeparam>
        /// <returns></returns>
        public static T Get<T>()
            where T : BizBase, new()
        {
            lock (lockStr)
            {
                Type t = typeof(T);
                if (!Svcs.ContainsKey(t))
                {
                    T re = new T();
                    Svcs.Add(t, re);
                }
                return Svcs[t] as T;
            }
        }
        #endregion 

        /// <summary>
        /// DBMain
        /// </summary>
        public static string DBMain
        {
            get { return AppConfigurtaion.GetSecondSection("ConnectionStrings", "con").ToString(); }
        }

        public static string DBMySql
        {
            get { return AppConfigurtaion.GetSecondSection("ConnectionStrings", "conMySql").ToString(); }
        }

        public static string WechatAppletAppId
        {
            get { return AppConfigurtaion.GetSecondSection("WechatApplet", "appid").ToString(); }
        }

        public static string WechatAppletSecret
        {
            get { return AppConfigurtaion.GetSecondSection("WechatApplet", "secret").ToString(); }
        }

        public static string VipWxAppId
        {
            get { return AppConfigurtaion.GetSecondSection("VipWxSetting", "appid").ToString(); }
        }

        public static string VipWxSecret
        {
            get { return AppConfigurtaion.GetSecondSection("VipWxSetting", "secret").ToString(); }
        }


        public static string Authorization_Code
        {
            get { return "authorization_code"; }
        }
    }
}
